/**
* 时间 : 2025.04.03:09.59.47
* 功能 :
* 用途 :
* 作者 : 村长偷包谷
**/


<template>
    <div id="supplierpro_Home" class="_home">
        <G_HomeHead :Config="_HadeConfig" />
        <G_QueryFun :Config="G_QueryFunConfig" ref="_QueryFun" />
        <el-table :data="P_Table" border
            style="margin-top: 12px; height: calc(100vh - 213px);cursor:default;width: 100%;">
            <el-table-column width="60px" type="index" label="序号" />
            <el-table-column v-for="o in columns" :prop="o.prop" :width="o.width" :label="o.label" />
            <el-table-column prop="auditFrequency" label="审核频次" width="120">
                <template #default="scope">
                    <el-tag :type="getFrequencyType(scope.row.auditFrequency)">
                        {{ getAuditFrequency(scope.row.auditFrequency) }}
                    </el-tag>
                </template>
            </el-table-column>
            <!-- <el-table-column width="160px" label="质量协议">
                <template #default="scope">
                    <el-dropdown v-if="scope.row.qualityAgreements.length">
                        <span class="el-dropdown-link">
                            {{ scope.row.qualityAgreements[0].agreementName }}
                            <el-icon class="el-icon--right" v-if="scope.row.qualityAgreements.length > 1">
                                <arrow-down />
                            </el-icon>
                        </span>
                        <template #dropdown v-if="scope.row.qualityAgreements.length > 1">
                            <el-dropdown-menu>
                                <el-dropdown-item v-for="o in scope.row.qualityAgreements"
                                @click="O_dropdownto(o,'second')"
                                    :key="o.qualityAgreementId">{{ o.agreementName }}</el-dropdown-item>
                            </el-dropdown-menu>
                        </template>
                    </el-dropdown>
                    <div v-else> - </div>
                </template>
            </el-table-column> -->
            <el-table-column width="160px" label="质量协议">
                <template #default="scope">

                    <div style="color:#67C23A;" v-if="scope.row.qualityAgreements.length"> {{ scope.row.qualityAgreements[0].versionDate }}
                    </div>

                    <div v-else> - </div>
                </template>
            </el-table-column>
            <!-- <el-table-column width="160px" label="质量协议审批">
                <template #default="scope">
                    <el-tag :type="scope.row.qualityAgreements[0]?.status == '1' ? 'success' : 'danger'">
                        {{ scope.row.qualityAgreements[0]?.status == '1' ? '已审批' : '未审批' }}
                    </el-tag>
                </template>
            </el-table-column> -->

            <!-- <el-table-column width="160px" label="ROSH协议">
                <template #default="scope">
                    <el-dropdown v-if="scope.row.roshAgreements.length">
                        <span class="el-dropdown-link">
                            {{ scope.row.roshAgreements[0].agreementName }}
                            <el-icon class="el-icon--right" v-if="scope.row.roshAgreements.length > 1">
                                <arrow-down />
                            </el-icon>
                        </span>
                        <template #dropdown v-if="scope.row.roshAgreements.length > 1">
                            <el-dropdown-menu>
                                <el-dropdown-item v-for="o in scope.row.roshAgreements" 
                                 @click="O_dropdownto(o,'rosh')"
                                :key="o.roshAgreementsId">{{

                                    o.agreementName }}</el-dropdown-item>
                            </el-dropdown-menu>
                        </template>
                    </el-dropdown>
                    <div v-else> - </div>
                </template>
            </el-table-column> -->
            <el-table-column width="160px" label="ROSH协议">
                <template #default="scope">
                    <div style="color:#67C23A;" v-if="scope.row.roshAgreements.length">

                        {{ scope.row.roshAgreements[0].versionDate }}
                    </div>
                    <div  v-else> - </div>
                </template>
            </el-table-column>
            <!-- <el-table-column width="160px" label="ROSH协议审批">
                <template #default="scope">
                    <el-tag :type="scope.row.roshAgreements[0]?.status == '1' ? 'success' : 'danger'">
                        {{ scope.row.roshAgreements[0]?.status == '1' ? '已审批' : '未审批' }}
                    </el-tag>
                </template>
            </el-table-column> -->





            <el-table-column width="160px" label="质量目标">
                <template #default="scope">
                    <el-dropdown v-if="scope.row.qualityObjectives.length">
                        <span class="el-dropdown-link">
                            {{ scope.row.qualityObjectives[0].qualityObjectivesName }}
                            <el-icon class="el-icon--right" v-if="scope.row.qualityObjectives.length > 1">
                                <arrow-down />
                            </el-icon>
                        </span>
                        <template #dropdown v-if="scope.row.qualityObjectives.length > 1">
                            <el-dropdown-menu>
                                <el-dropdown-item v-for="o in scope.row.qualityObjectives"
                                  @click="O_dropdownto(o,'fourth1')"
                                    :key="o.qualityObjectivesId">{{ o.qualityObjectivesName }}</el-dropdown-item>
                            </el-dropdown-menu>
                        </template>
                    </el-dropdown>
                    <div v-else> - </div>
                </template>
            </el-table-column>

            <!-- <el-table-column width="160px" label="质量目标">
                <template #default="scope">
                    <el-tag :type="scope.row.qualityObjectives[0]?.status == '1' ? 'success' : 'danger'">
                        {{ scope.row.qualityObjectives[0]?.status == '1' ? '已审批' : '未审批' }}
                    </el-tag>
                </template>
            </el-table-column> -->




            <el-table-column width="160px" label="审核计划">
                <template #default="scope">
                    <el-dropdown v-if="scope.row.examines.length">
                        <span class="el-dropdown-link">
                            {{ scope.row.examines[0].examineDate }}
                            <el-icon class="el-icon--right" v-if="scope.row.examines.length > 1">
                                <arrow-down />
                            </el-icon>
                        </span>
                        <template #dropdown v-if="scope.row.examines.length > 1">
                            <el-dropdown-menu>
                                <el-dropdown-item v-for="o in scope.row.examines" 
                                  @click="O_dropdownto(o,'fourth2')"
                                :key="o.examineId">{{ o.examineDate
                                }}</el-dropdown-item>
                            </el-dropdown-menu>
                        </template>
                    </el-dropdown>
                    <div v-else> - </div>
                </template>
            </el-table-column>
            <el-table-column width="160px" label="审核定级">
                <template #default="scope">
                    <div v-if="scope.row.examines.length"> {{ scope.row.examines[0]?.examineLevel }}</div>
                    <div v-else> - </div>
                </template>
            </el-table-column>
            <el-table-column width="160px" label="完成证据附件">
                <template #default="scope">
                    <div v-if="scope.row.examines.length">
                        <el-tag v-for="e in scope.row.examines[0].annexFiles" type="primary">{{ e.uploadFileName
                        }}</el-tag>
                    </div>
                    <div v-else>
                         - 
                    </div>
                </template>
            </el-table-column>
            <!-- <el-table-column width="160px" label="审核计划审批">
                <template #default="scope">
                    <el-tag :type="scope.row.examines[0]?.status == '1' ? 'success' : 'danger'">
                        {{ scope.row.examines[0]?.status == '1' ? '已审批' : '未审批' }}
                    </el-tag>
                </template>
            </el-table-column> -->


            <el-table-column width="160px" label="问题是否关闭">
                <template #default="scope">
                    <div v-if="scope.row.auditIssues.length">
                        <el-tag :type="scope.row.auditIssues[0].close == 'YES' ? 'success' : 'danger'">
                            {{ scope.row.auditIssues[0].close }}
                        </el-tag>
                    </div>
                    <div v-else>
                         - 
                    </div>
                </template>
            </el-table-column>
            <el-table-column width="160px" label="关闭证据附件">
                <template #default="scope">
                    <div v-if="scope.row.auditIssues.length">
                        <el-tag v-for="e in scope.row.auditIssues[0].annexFiles" type="primary">{{ e.uploadFileName
                        }}</el-tag>
                    </div>
                    <div v-else>
                         - 
                    </div>
                </template>
            </el-table-column>
            <!-- <el-table-column width="160px" label="问题关闭审批">
                <template #default="scope">
                    <el-tag :type="scope.row.auditIssues[0]?.status == '1' ? 'success' : 'danger'">
                        {{ scope.row.auditIssues[0]?.status == '1' ? '已审批' : '未审批' }}
                    </el-tag>
                </template>
            </el-table-column> -->

            <el-table-column label="操作" width="140px" fixed="right">
                <template #default="scope">
                    <el-button type="primary" link @click="operation('1', scope.row)">
                        <el-icon>
                            <Edit />
                        </el-icon>
                        编辑
                    </el-button>
                    <el-button type="danger" link @click="operation('0', scope.row)">
                        <el-icon>
                            <Delete />
                        </el-icon>
                        删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <G_Paging v-show="P_PagingConfig" :Config="{ ...P_PagingConfig, PagingChange }" />
    </div>
</template>

<script setup>
import { ref, onMounted } from "vue"
import { columns, _HadeConfig, _QueryBtnConfig, _FilterConfig } from "../Config.js"
import { ElMessageBox, ElMessage } from 'element-plus'
import P_store from "@store/supplierpro/index.js"
import { storeToRefs } from "pinia"
import { useRouter } from 'vue-router'
const P = P_store()
const R = useRouter()
const { P_Params, P_Table, P_PagingConfig,activeName } = storeToRefs(P)



const getFrequencyType = (frequency) => {
    const typeMap = {
        '一年两次': 'success',    // 一年两次显示绿色
        '两年一次': 'warning',        // 两年一次显示黄色
        '半年一次': 'danger'  ,       // 半年一次显示蓝色
        '三年一次': 'info'
    }
    return typeMap[frequency]
}

const G_QueryFunConfig = ref({
    ..._QueryBtnConfig,
    _FilterConfig,
    Send_Form: (_form) => {

        const hasNonEmptyValues = Object.values(_form).some(value =>
            value !== '' && value !== null && value !== undefined
        )

        if (hasNonEmptyValues) {
            P_Params.value = {
                pageNumber: 0,
                pageSize: 30,
                ..._form
            }

        } else {
            P_Params.value = {
                pageNumber: 0,
                pageSize: 30,
            }
        }


        console.log("过来", P_Params.value);

        P.Hp_GetSearch()

    },
    O_Feature: (data) => {
        handleFeature(data)
    }
})
const _QueryFun = ref(null)

const getAuditFrequency = (frequency) => {
    const frequencyMap = {
        'YEARLY_TWICE': '一年两次',
        'BIENNIAL': '两年一次',
        'SEMI_ANNUAL': '半年一次'
    }
    return frequencyMap[frequency] || frequency
}
const operation = (type, row) => {
    console.log(type, row);

    if (type == '1') {
        // P.Hp_GetIdSee(row.subComponentsId)
        R.push('/supplierpro/homeform/' + row.supplierId)
    } else {
        ElMessageBox.confirm(
            '确认要删除该记录吗？',
            '警告',
            {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }
        ).then(() => {
            P.Hp_Del(row.supplierId)

        }).catch(() => {
            ElMessage.info('已取消删除')
        })

    }
}


onMounted(() => {
    P.Hp_GetSearch()
})

// 分页切换
const PagingChange = (type, val) => {
    console.log(type, val);
    type ? P_Params.value.pageNumber = val : P_Params.value.pageSize = val;
    P.Hp_GetSearch()
}


const O_dropdownto = (o,name)=>{

    activeName.value = name
    R.push('/supplierpro/homeform/' + o.supplierId)
}

</script>

<style lang="less">
#supplierpro_Home {}
</style>